/*
 * @Author: your name
 * @Date: 2021-04-18 11:33:24
 * @LastEditTime: 2021-05-01 15:51:46
 * @LastEditors: Please set LastEditors
 * @Description: 点餐界面中间的listview
 * @FilePath: /first_flutter_app/lib/views/orderPage/orderMiddleListView.dart
 */

import 'package:first_flutter_app/constant/dataInfo.dart';
import 'package:first_flutter_app/controller/orderPageController.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class MiddlePageShow extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return _listSetting(context);
  }

  Widget _listSetting(BuildContext context) {
    return Container(
      width: 200.w,
      padding: EdgeInsets.all(25.sp),
      decoration: BoxDecoration(
        color: Color.fromRGBO(243, 245, 247, 1.5),
        border: Border.all(
          color: Color.fromRGBO(233, 236, 245, 1),
        ),
      ),
      child: Column(
        children: [
          _plusDesProductContainer(),
          _listProductSetting(context),
          Divider(color: Colors.black45),
          _listOrderSetting(context),
        ],
      ),
    );
  }

  // 商品加减组件
  Widget _plusDesProductContainer() {
    return Container(
      height: 350.h,
      child:
        Column(
          children: [
            Container(
              width: 156.w,
              height: 200.h,
              decoration: BoxDecoration(
                  color: Colors.white,
                  border: Border.all(
                    color: Colors.black12,
                  )),
              child: Center(
                child: GetBuilder<OrderController>(
                  builder: (_) => Text(
                    OrderController.oc.productOrderCount.toString(),
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(80),
                      color: Colors.blue,
                    ),
                  ),
                ),
              ),
            ),
            Container(
              margin: EdgeInsets.only(
                left: 20.sp,
                // bottom: 20.sp
              ), child: Row(
                  children: [
                    GetBuilder<OrderController>(
                      builder: (_) => InkWell(
                        onTap: () {
                          OrderController.oc.desProductOrderCount();
                        },
                        child: Container(
                          width: 78.w,
                          height: 120.h,
                          decoration: BoxDecoration(
                              color: Colors.white,
                              border: Border.all(
                                color: Colors.black12,
                              )),
                          child: Icon(
                            Icons.remove,
                            color: Colors.black45,
                          ),
                        ),
                      ),
                    ),
                    GetBuilder<OrderController>(
                      builder: (_) => InkWell(
                        onTap: () {
                          OrderController.oc.plusProductOrderCount();
                        },
                        child: Container(
                          width: 78.w,
                          height: 120.h,
                          decoration: BoxDecoration(
                              color: Colors.white,
                              border: Border.all(
                                color: Colors.black12,
                              )),
                          child: Icon(
                            Icons.add,
                            color: Colors.black45,
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
            ),
          ],
      )
    );
  }

  Widget _listProductSetting(BuildContext context) {
    return Container(
      // width: ScreenUtil().setWidth(80),
      height: 725.h,
      child: MediaQuery.removePadding(
        context: context,
        removeTop: true,
        child: ListView.builder(
          itemBuilder: (context, index) {
            return Container(
              margin: EdgeInsets.all(ScreenUtil().setSp(20)),
              child: ElevatedButton(
                onPressed: () {},
                style: ButtonStyle(
                  minimumSize: MaterialStateProperty.all(Size(120, 50)),
                  backgroundColor: MaterialStateProperty.resolveWith((states) {
                    //设置按下时的背景颜色
                    if (states.contains(MaterialState.pressed)) {
                      return Colors.blue[800];
                    }
                    //默认不使用背景颜色
                    return Colors.white;
                  }),
                ),
                child: Text(
                  productSetting[index],
                  style: TextStyle(
                    color: Colors.black45,
                    fontWeight: FontWeight.w900,
                    fontSize: ScreenUtil().setSp(60),
                  ),
                ),
              ),
            );
          },
          itemCount: productSetting.length,
        ),
      )
    );
  }

  Widget _listOrderSetting(BuildContext context) {
    return Container(
      height: 725.h,
      // width: ScreenUtil().setWidth(80),
      child: MediaQuery.removePadding(
        context: context,
        removeTop: true,
        child: ListView.builder(
          itemBuilder: (context, index) {
            return GetBuilder<OrderController>(
              builder: (_) => Container(
                margin: EdgeInsets.all(10.sp),
                child: ElevatedButton(
                  onPressed: () {
                    showDialog(
                      context: context,
                      builder: (BuildContext context) {
                        return AlertDialog(
                          title: Text(
                            '警告',
                            style: TextStyle(
                              color: Colors.blueAccent,
                              fontSize: 25.sp,
                            ),
                          ),
                          content: Text(
                            '是否确定删除这些菜品?',
                            style: TextStyle(
                              color: Colors.black54,
                              fontSize: 25.sp,
                            ),
                          ),
                          actions: [
                            GetBuilder<OrderController>(
                              builder: (_) => ElevatedButton(
                                onPressed: () {
                                  OrderController.oc.deleteSelectProductList();
                                  Navigator.pop(context);
                                },
                                child: Text(
                                  "确定",
                                  style: TextStyle(
                                    fontSize: 30.sp,
                                  ),
                                ),
                              ),
                            ),
                            ElevatedButton(
                              onPressed: () {
                                Navigator.pop(context);
                              },
                              style: ButtonStyle(
                                backgroundColor:
                                    MaterialStateProperty.resolveWith((states) {
                                  //设置按下时的背景颜色
                                  if (states.contains(MaterialState.pressed)) {
                                    return Colors.blue;
                                  }
                                  //默认不使用背景颜色
                                  return Colors.green;
                                }),
                              ),
                              child: Text(
                                "取消",
                                style: TextStyle(
                                  fontSize: ScreenUtil().setSp(30),
                                ),
                              ),
                            ),
                          ],
                        );
                      },
                    );
                  },
                  style: ButtonStyle(
                    // minimumSize: MaterialStateProperty.all(Size(120, 50)),
                    backgroundColor: MaterialStateProperty.resolveWith((states) {
                      //设置按下时的背景颜色
                      if (states.contains(MaterialState.pressed)) {
                        return Colors.blue[800];
                      }
                      //默认不使用背景颜色
                      return Colors.white;
                    }),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      orderSetting[index][0],
                      Text(
                        orderSetting[index][1],
                        style: TextStyle(
                          color: Colors.black45,
                          fontSize: 45.sp,
                          fontWeight: FontWeight.w900,
                        ),
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ],
                  ),
                ),
              ),
            );
          },
          itemCount: orderSetting.length,
        ),
      )
    );
  }
}
